package org.ezplatform.office.meeting.search.web.rest;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.ezplatform.cloud.common.controller.BaseController;
import org.ezplatform.core.web.view.OperationResult;
import org.ezplatform.office.meeting.search.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

/**
 * 
 *会议管理--会议查询
 *
 */
@RestController
@RequestMapping("api/meeting/search")
public class SearchApiController extends BaseController {
    
    @Autowired
    private SearchService searchService;
    
    
    /**
     * 查询我发起的会议数据
     */
    @ApiOperation(value="会议查询", notes="查询我发起的会议list列表数据信息")
    @ApiImplicitParams({
    	@ApiImplicitParam(name = "userId", value = "当前用户ID", required = true, paramType = "query", dataType = "String"),
    	@ApiImplicitParam(name = "corpId", value = "单位ID", required = true, paramType = "query", dataType = "String"),
    	@ApiImplicitParam(name = "token", value = "token", required = true, paramType = "query", dataType = "String"),
        @ApiImplicitParam(name = "page", value = "当前显示页数", required = true, paramType = "query", dataType = "String"),
        @ApiImplicitParam(name = "pageSize", value = "一页显示数", required = true, paramType = "query", dataType = "String"),
        @ApiImplicitParam(name = "condition", value = "查询条件", required = true, paramType = "query", dataType = "String")
    })
    @RequestMapping(value = "/createApplyRecordList", method = RequestMethod.GET,produces={"application/json; charset=UTF-8"})
    public OperationResult getCreateApplyRecordList(HttpServletRequest request) {
    	Map<String,Object> map = new HashMap<String,Object>();
    	try{
            //当前页
            String currentPage = request.getParameter("page");
            //一页显示条数
            String pageSize = request.getParameter("pageSize");
            //查询条件
            String condition = request.getParameter("condition");
            //用户ID
            String userId = request.getParameter("userId");
            //用户单位
            String corpId = request.getParameter("corpId");
            String token = request.getParameter("token");
            
//            List<Map> list = this.searchService.getApplyRecordList(currentPage, pageSize,userId,corpId,condition,0,"0",token);
            List<Map> list = this.searchService.getApplyRecordListOfMine(currentPage, pageSize,userId,corpId,condition,token);
            map.put("data", list);
            map.put("currentPage", Integer.parseInt(currentPage));
           
        }catch(Exception e){
        	return OperationResult.buildFailureResult("获取失败");
        }
    	return OperationResult.buildSuccessResult(map);
    }
    
    /**
     * 查询我参与的会议数据
     */
    @ApiOperation(value="会议查询", notes="查询我参与的会议list列表数据信息")
    @ApiImplicitParams({
    	@ApiImplicitParam(name = "userId", value = "当前用户ID", required = true, paramType = "query", dataType = "String"),
    	@ApiImplicitParam(name = "corpId", value = "单位ID", required = true, paramType = "query", dataType = "String"),
    	@ApiImplicitParam(name = "token", value = "token", required = true, paramType = "query", dataType = "String"),
        @ApiImplicitParam(name = "page", value = "当前显示页数", required = true, paramType = "query", dataType = "String"),
        @ApiImplicitParam(name = "pageSize", value = "一页显示数", required = true, paramType = "query", dataType = "String"),
        @ApiImplicitParam(name = "condition", value = "查询条件", required = true, paramType = "query", dataType = "String")
    })
    @RequestMapping(value = "/attendApplyRecordList", method = RequestMethod.GET,produces={"application/json; charset=UTF-8"})
    public OperationResult getAttendApplyRecordList(HttpServletRequest request) {
    	Map<String,Object> map = new HashMap<String,Object>();
        try{
            //当前页
            String currentPage = request.getParameter("page");
            //一页显示条数
            String pageSize = request.getParameter("pageSize");
            //查询条件
            String condition = request.getParameter("condition"); 
            //用户ID
            String userId = request.getParameter("userId");
            //用户单位
            String corpId = request.getParameter("corpId");
            String token = request.getParameter("token");
//            List<Map> list = this.searchService.getApplyRecordList(currentPage, pageSize, userId, corpId, condition, 1, "0",token);
            List<Map> list = this.searchService.getApplyRecordListOfMine(currentPage, pageSize, userId, corpId, condition, token);
            map.put("data", list);
            map.put("currentPage", Integer.parseInt(currentPage));
           
        }catch(Exception e){
        	return OperationResult.buildFailureResult("获取失败");
        }
        return OperationResult.buildSuccessResult(map);
    }
    
    /**
     * 查询我的周期会议
     */
    @ApiOperation(value="周期会议查询", notes="查询与我有关的周期会议列表数据信息")
    @ApiImplicitParams({
    	@ApiImplicitParam(name = "userId", value = "当前用户ID", required = true, paramType = "query", dataType = "String"),
    	@ApiImplicitParam(name = "corpId", value = "单位ID", required = true, paramType = "query", dataType = "String"),
    	@ApiImplicitParam(name = "token", value = "token", required = true, paramType = "query", dataType = "String"),
        @ApiImplicitParam(name = "page", value = "当前显示页数", required = true, paramType = "query", dataType = "String"),
        @ApiImplicitParam(name = "pageSize", value = "一页显示数", required = true, paramType = "query", dataType = "String"),
        @ApiImplicitParam(name = "condition", value = "查询条件", required = true, paramType = "query", dataType = "String")
    })
    @RequestMapping(value = "/getCycleMeetingList", method = RequestMethod.GET,produces={"application/json; charset=UTF-8"})
    public OperationResult getCycleMeetingList(HttpServletRequest request) {
    	Map<String,Object> map = new HashMap<String,Object>();
        try{
            //当前页
            String currentPage = request.getParameter("page");
            //一页显示条数
            String pageSize = request.getParameter("pageSize");
            //查询条件
            String condition = request.getParameter("condition"); 
            //用户ID
            String userId = request.getParameter("userId");
            //用户单位
            String corpId = request.getParameter("corpId");
            String token = request.getParameter("token");
            List<Map> list = this.searchService.getCycleMeetingListOfMine(currentPage, pageSize, userId, corpId, condition, token);
            map.put("data", list);
            map.put("currentPage", Integer.parseInt(currentPage));
           
        }catch(Exception e){
        	return OperationResult.buildFailureResult("获取失败");
        }
        return OperationResult.buildSuccessResult(map);
    }
    
    /**
     * 根据周期会议id查询周期会议
     */
    @ApiOperation(value="周期会议查询", notes="根据周期会议id查询周期会议")
    @ApiImplicitParams({
    	@ApiImplicitParam(name = "userId", value = "当前用户ID", required = true, paramType = "query", dataType = "String"),
    	@ApiImplicitParam(name = "corpId", value = "单位ID", required = true, paramType = "query", dataType = "String"),
    	@ApiImplicitParam(name = "token", value = "token", required = true, paramType = "query", dataType = "String"),
        @ApiImplicitParam(name = "page", value = "当前显示页数", required = true, paramType = "query", dataType = "String"),
        @ApiImplicitParam(name = "pageSize", value = "一页显示数", required = true, paramType = "query", dataType = "String"),
        @ApiImplicitParam(name = "condition", value = "查询条件", required = true, paramType = "query", dataType = "String"),
        @ApiImplicitParam(name = "cycleId", value = "周期会议ID", required = true, paramType = "query", dataType = "String")
    })
    @RequestMapping(value = "/getCycleMeetingByCycleId", method = RequestMethod.GET,produces={"application/json; charset=UTF-8"})
    public OperationResult getCycleMeetingByCycleId(HttpServletRequest request) {
    	Map<String,Object> map = new HashMap<String,Object>();
        try{
            //当前页
            String currentPage = request.getParameter("page");
            //一页显示条数
            String pageSize = request.getParameter("pageSize");
            //查询条件
            String condition = request.getParameter("condition"); 
            //用户ID
            String userId = request.getParameter("userId");
            //用户单位
            String corpId = request.getParameter("corpId");
            String token = request.getParameter("token");
            String cycleId = request.getParameter("cycleId"); 
            List<Map> list = this.searchService.getCycleMeetingByCycleId(currentPage, pageSize, userId, corpId, condition, cycleId, token);
            map.put("data", list);
            map.put("currentPage", Integer.parseInt(currentPage));
           
        }catch(Exception e){
        	return OperationResult.buildFailureResult("获取失败");
        }
        return OperationResult.buildSuccessResult(map);
    }
}